// import { stringify } from "querystring";

let list = [
  { id: 0, timestamp: new Date().valueOf(), author: '111', status: 0 },
  { id: 1, timestamp: new Date().valueOf(), author: '222', status: 1 },
  { id: 2, timestamp: new Date().valueOf(), author: '333', status: 2 },
  { id: 3, timestamp: new Date().valueOf(), author: '444', status: 0 },
  { id: 4, timestamp: new Date().valueOf(), author: '555', status: 1 },
  { id: 5, timestamp: new Date().valueOf(), author: '666', status: 0 },
  { id: 6, timestamp: new Date().valueOf(), author: '777', status: 1 }
]
export default [
  // 查询
  {
    url: '/bdc/manual-operate',
    type: 'get',
    response: config => {
      // mock error
      // if (!token) {
      //   return {
      //     code: 60204,
      //     message: 'Account and password are incorrect.'
      //   }
      // }
      const res = config.query
      let data = [].concat(list)
      if (res.author && res.author !== '') {
        data = data.filter(a => a.author.indexOf(res.author) >= 0)
      }
      if (res.status && res.status !== '') {
        data = data.filter(a => Number(a.status) === Number(res.status))
      }
      return {
        code: 20000,
        data: data,
        message: JSON.stringify(res)
      }
    }
  },
  // 创建数据
  {
    url: '/bdc/manual-operate',
    type: 'post',
    response: config => {
      const item = config.body
      list.unshift(item)
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  // 编辑数据
  {
    url: '/bdc/manual-operate',
    type: 'put',
    response: config => {
      const item = config.body
      const index = list.indexOf(list.find(a => a.id === item.id))
      list[index] = item
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  // 删除数据
  {
    url: '/bdc/manual-operate/[A-Za-z0-9]',
    type: 'delete',
    response: config => {
      const id = config.url.split('/')[config.url.split('/').length - 1]
      list = list.filter(a => a.id !== Number(id))
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
